import discord
from discord.ext import commands
import func
import os

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)


@bot.command()
async def sync(ctx):
  await bot.tree.sync()
  await ctx.send('同步完成')


# @bot.event
# async def on_ready():
#     await bot.tree.sync()
#     print(f'Logged in as {bot.user} (ID: {bot.user.id})')
#     print('同步成功') # 为了让服务器知道/指令，而不是!指令


@bot.hybrid_command()
async def hello(ctx):
  await ctx.send('hello master')


@bot.command()
async def add(ctx, a: int, b: int):
  await ctx.send(a + b)


@bot.command()
async def how(ctx):
  """获取帮助"""
  s = func.help()
  await ctx.send(s)


@bot.command()
async def q(ctx, 当前地图前三个英文字母, 当前模式首字母, 当前第几张地图, 下张地图前三个英文字母, 下张地图模式首字母,
            下张地图第几张地图, 当前阵营英语缩写):
  """查询下一场比赛载具信息，不区分大小写"""
  a, b, c, d, e, f, g = 当前地图前三个英文字母, 当前模式首字母, 当前第几张地图, 下张地图前三个英文字母, 下张地图模式首字母, 下张地图第几张地图, 当前阵营英语缩写
  try:
    ret = ''
    now_info, all_team_info = func.work(a, b, c, d, e, f, g)
    team1_info, team2_info = all_team_info
    ret += f'# {now_info}\n'
    ret += '--------------------------------------------\n'
    for i, it in enumerate(team1_info):
      if i == 0:
        ret += f'下一场你是 {it} 阵营\n'
        continue
      ret += f'{it}\n'

    ret += '--------------------------------------------\n'
    for i, it in enumerate(team2_info):
      if i == 0:
        ret += f'下一场对面是 {it} 阵营\n'
        continue
      ret += f'{it}\n'

    await ctx.reply(ret)
  except Exception as e:
    await ctx.reply('有可能格式有问题，也有可能阵营等信息输错了')


#my_token = os.getenv('DISCORD1_TOKEN')
#if my_token is None:
#  assert False

bot.run(token=)
